package com.gc.cscott.verify.contest2012Sep;

import com.gc.cscott.verify.JavaTaskOutputVerifier;
import com.gc.cscott.verify.OutputVerifier.VerifiedOutput;
import java.awt.geom.Point2D;


/**
 *
 * @author astukalin
 */
public class Z1Ellipsis implements JavaTaskOutputVerifier {

    public VerifiedOutput verify(String inputText, String outputText, String validationHintText) {
        String[] outputLines = outputText.split("\n");
        String[] hintLines = validationHintText.split("\n");

        if (outputLines.length < 4) {
            VerifiedOutput.outputIsWrong("We need 4 strings in the output file");
        }

        if (!outputLines[0].equalsIgnoreCase(hintLines[0]) ) {
            return VerifiedOutput.outputIsWrong("Expected "+hintLines[0]+", but was "+outputLines[0]);
        }

        for (int i = 1; i < 3; i++) {
            if (!parsePoint(outputLines[i]).equals(parsePoint(hintLines[i]))) {
                return VerifiedOutput.outputIsWrong("In line "+(i+1)+" expected "+hintLines[i]+", but was "+outputLines[i]);
            }
        }

        if (Double.parseDouble(outputLines[3]) != Double.parseDouble(hintLines[3])) {
            return VerifiedOutput.outputIsWrong("In line 4 expected "+hintLines[3]+", but was "+outputLines[3]);
        }

        return VerifiedOutput.outputIsCorrect();
    }

    Point2D parsePoint(String line) {
        line = line.trim();
        String[] items = line.split("\\s+");
        String x = items[0];
        String y = items[1];
        return new Point2D.Double(Double.parseDouble(x), Double.parseDouble(y));
    }
}
